<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Evaluates the given XPath expression and returns a typed result if possible</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="domxpath.construct.html">DOMXPath::__construct</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="domxpath.query.html">DOMXPath::query</a></div>
 <div class="up"><a href="class.domxpath.html">DOMXPath</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="domxpath.evaluate" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DOMXPath::evaluate</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0)</p><p class="refpurpose"><span class="refname">DOMXPath::evaluate</span> &mdash; <span class="dc-title">
   Evaluates the given XPath expression and returns a typed result if possible
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-domxpath.evaluate-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>DOMXPath::evaluate</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$expression</code></span>
   [, <span class="methodparam"><span class="type"><a href="class.domnode.html" class="type DOMNode">DOMNode</a></span> <code class="parameter">$contextnode</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$registerNodeNS</code><span class="initializer"> = true</span></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Executes the given XPath <em><code class="parameter">expression</code></em> and returns
   a typed result if possible.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-domxpath.evaluate-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">expression</code></em></dt>

     <dd>

      <p class="para">
       The XPath expression to execute.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">contextnode</code></em></dt>

     <dd>

      <p class="para">
       The optional <em><code class="parameter">contextnode</code></em> can be specified for
       doing relative XPath queries. By default, the queries are relative to 
       the root element.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">registerNodeNS</code></em></dt>

     <dd>

      <p class="para">
       The optional <em><code class="parameter">registerNodeNS</code></em> can be specified to 
       disable automatic registration of the context node.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-domxpath.evaluate-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a typed result if possible or a <a href="class.domnodelist.html" class="classname">DOMNodeList</a> 
   containing all nodes matching the given XPath <em><code class="parameter">expression</code></em>. 
  </p>
  <p class="para">
   If the <em><code class="parameter">expression</code></em> is malformed or the
   <em><code class="parameter">contextnode</code></em> is invalid,
   <span class="methodname"><strong>DOMXPath::evaluate()</strong></span> returns <strong><code>FALSE</code></strong>.
  </p>
 </div>

 <div class="refsect1 changelog" id="refsect1-domxpath.evaluate-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.3.3</td>
       <td>
         The <em><code class="parameter">registerNodeNS</code></em> parameter was added.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-domxpath.evaluate-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5314">
    <p><strong>Example #1 Getting the count of all the english books</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$doc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">load</span><span style="color: #007700">(</span><span style="color: #DD0000">'book.xml'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$xpath&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DOMXPath</span><span style="color: #007700">(</span><span style="color: #0000BB">$doc</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$tbody&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getElementsByTagName</span><span style="color: #007700">(</span><span style="color: #DD0000">'tbody'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">item</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;our&nbsp;query&nbsp;is&nbsp;relative&nbsp;to&nbsp;the&nbsp;tbody&nbsp;node<br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'count(row/entry[.&nbsp;=&nbsp;"en"])'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$entries&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$xpath</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">evaluate</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$tbody</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"There&nbsp;are&nbsp;</span><span style="color: #0000BB">$entries</span><span style="color: #DD0000">&nbsp;english&nbsp;books\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
There are 2 english books
</pre></div>
    </div>
   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-domxpath.evaluate-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="domxpath.query.html" class="methodname" rel="rdfs-seeAlso">DOMXPath::query()</a> - Evaluates the given XPath expression</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="domxpath.construct.html">DOMXPath::__construct</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="domxpath.query.html">DOMXPath::query</a></div>
 <div class="up"><a href="class.domxpath.html">DOMXPath</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
